import axios from '@/utils/request'
export default {
  Team: {
    list: {
      list_filter: {
        'store.id': () => {
          return axios
            .get(`/manage/stores`)
            .then(res =>
              Object.assign({ __label: '门店' },
                ...res.data.map(v => { return { [v.id]: v.name } })))
        },
        name: {
          expression: `entity.getName() matches ":value"`,
          label: '团队名称',
          type: 'input'
        }
      },
      list_display: [
        'name',
        'store',
        { property: 'broker', label: '经纪人' },
        'enabled'
      ]
    },
    form: {
      fields: [
        'name',
        'store',
        {
          property: 'broker',
          field_options: { label: '经纪人' },
          required: false,
          help: '经纪人分佣会自动到经纪人绑定的钱包',
          component: {
            props: ['form', 'property'],
            data() {
              return { data: [] }
            },
            created() {
              axios.get(`/manage/staffs`, {
                params: {
                  'limit': 1000000
                }
              }).then((res) => {
                this.data = res.data
              })
            },
            render(h) {
              return (
                <el-select v-model={this.form[this.property]} clearable filterable>{
                  Object.assign(this.data).map(v => {
                    return <el-option key={v.id} label={v.name + '(' + v.phone + ')'} value={v.id} />
                  })
                }</el-select>
              )
            }
          }
        },
        { property: 'enabled', default_value: true }
      ]
    }
  }
}

